const DB = require('../../utils/db');

module.exports = {
	messageList: async (pageNum, pageSize, keywords) => {
		let [allList] = await DB.query(`select * from t_msg where ip like '%${keywords}%'`);

		let arr = [(pageNum - 1) * pageSize, pageSize];
		let [list] = await DB.query(
			`
                  select m.*, date_format(m.createTime,'%Y-%m-%d %H:%i:%s') as createTime, u.username 
                  from t_msg m 
                  left join t_user u 
                  on m.userId = u.id
                  where m.ip like '%${keywords}%' order by m.createTime desc limit ?,?`,
			arr
		);
		return { data: list, total: allList.length };
	},
	messageDel: async (ids) => {
		let data = await DB.query('delete from t_msg where id in (?)', [ids]);
		return data;
	}
};
